#include <iostream>
#include<list>
#include<algorithm>
using namespace std;
void print(const list<int> &l)
{
    list<int>::const_iterator it=l.begin();
    while(it!=l.end())
    {
        cout<<*it<<" ";
        it++;
    }
    cout<<endl;
}
void hjx1()
{
    list<int> l;
    l.push_back(1);
    l.push_back(2);
    l.push_back(3);
    l.push_back(4);
    l.push_back(5);
    list<int>::iterator pos=find(l.begin(),l.end(),3);
    if(pos!=l.end())
    {
        l.insert(pos,30);
        l.erase(pos);
    }

    print(l);
}
void hjx2()
{
    list<int> l;
    l.push_back(1);
    l.push_back(2);
    l.push_back(3);
    l.push_back(4);
    l.push_back(5);
    list<int> lt;
    lt.push_back(10);
    lt.push_back(20);
    lt.push_back(30);
    lt.push_back(40);
    lt.push_back(50);
    l.splice(l.begin(),lt);
    print(l);
    print(lt);//lt变空
}
void hjx3()
{
    list<int> l;
    l.push_back(3);
    l.push_back(9);
    l.push_back(6);
    l.push_back(1);
    l.push_back(78);
    l.sort();
    print(l);
}
void hjx4()
{
    list<int> l;
    l.push_back(1);
    l.push_back(2);
    l.push_back(3);
    l.push_back(4);
    l.push_back(5);
    list<int> ::iterator it=l.begin();
    while(it!=l.end())
    {
        if(*it%2==0)
        {
            it=l.erase(it);
        }
        else
        {
            it++;
        }
    }
    print(l);
}
int main()
{
//    hjx1();
//    hjx2();
//    hjx3();//排序
      hjx4();//迭代器失效
    return 0;
}

















